import 'package:auntserver/model/beans.dart';
import 'package:auntserver/model/entitys.dart';
import 'package:auntserver/net_api/aunt_datas.dart';
import 'package:auntserver/utils/aunt_utils.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

class OrderDetailScreen extends StatefulWidget {
  final String orderType;
  final String orderId;
  final String auntid;

  const OrderDetailScreen(
      {Key key,
      @required this.orderId,
      @required this.orderType,
      @required this.auntid})
      : super(key: key);

  @override
  _OrderDetailScreenState createState() => _OrderDetailScreenState();
}

class _OrderDetailScreenState extends State<OrderDetailScreen> {
  String _currentOrderId;
  String _type;
  Future _future;
  AuntEntity auntEntity;
  ChooseIdentity chooseIdentity;
  OrderDetailEntity _orderDetailEntity;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _currentOrderId = widget.orderId;
    _type = widget.orderType;
  }

  @override
  void didChangeDependencies() {
    super.didChangeDependencies();
    auntEntity = Provider.of<AuntEntity>(context);
    chooseIdentity = Provider.of<ChooseIdentity>(context);
    _future = getOrderDetail();
  }

  Future<OrderDetailEntity> getOrderDetail() async{
    AuntData.requestOrderDetail(
            _currentOrderId,
            auntEntity.userinfo.userid.toString(),
            chooseIdentity.status.toString(),
            _type,
            auntEntity?.userinfo?.accesstoken,
            auntId: widget.auntid)
        .then((value) {
      if (value is OrderDetailEntity) {
        _orderDetailEntity = value;
      }
    });
    return _orderDetailEntity;
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: PreferredSize(
        preferredSize: Size.fromHeight(44),
        child: AppBar(
          centerTitle: true,
          title: GestureDetector(
            child: Text('订单详情'),
            onDoubleTap: () {
              setState(() {
                _future = getOrderDetail();
              });
            },
          ),
        ),
      ),
      body: FutureBuilder<OrderDetailEntity>(
          future: _future,
          builder: (BuildContext context, AsyncSnapshot<OrderDetailEntity> snapshot) {
            return FutureLoadingWidget<OrderDetailEntity>(async: snapshot,widgetBuilder: (context,data){
              return Column(
                children: [
                  Center(
                    child: GestureDetector(
                      child: Text(data.orderInfo.orderid.toString()+widget.orderId),
                      onTap: () {},
                    ),
                  ),
                ],
              );
            },);

          }),
    );
  }
}
